let app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    active: 0,
    type_nickName: '律所',
    office_info: {},
    lawyer_info: {},
    enterprise_info: {},
    domainName: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getData()
  },
  onShareAppMessage(){
    let title = "",path="",id=wx.getStorageSync('uid');
    if(this.data.type_nickName == "律所"){
      title="邀请律所";
      path="/packageI/lawyerPlatform/info/info?type=officedetail&share=office&merchant_member_id="+id
    }else if(this.data.type_nickName == '律师'){
      title="邀请律师";
      path="/packageI/lawyerPlatform/info/info?type=lawyerdetail&share=lawyer&merchant_member_id="+id;
    }else{
      title="邀请企业";
      path="/packageI/lawyerPlatform/enterprise/add/add?type=add&share=enterprise&merchant_member_id="+id;
    }
    return {
      title,
      path
    }
  },
  getData() {
    let urlStr = "";
    if (this.data.type_nickName == '律所') {
      urlStr = app.getNetAddresss("plugin.lawyer-platform.frontend.controllers.merchant.getLawyerFirm");
    } else if (this.data.type_nickName == '律师') {
      urlStr = app.getNetAddresss("plugin.lawyer-platform.frontend.controllers.merchant.getLawyer");
    } else {
      urlStr = app.getNetAddresss("plugin.lawyer-platform.frontend.controllers.business.getBusiness");
    }
    app._postNetWork({
      url: urlStr,
      success: (res) => {
        if (res.data.result == 1) {
          if (this.data.type_nickName == '律所') {
            this.setData({
              office_info: res.data.data.list
            })
          } else if (this.data.type_nickName == '律师') {
            this.setData({
              lawyer_info: res.data.data.list
            })
          } else {
            this.setData({
              enterprise_info: res.data.data.list
            })
          }
        } else {
          app.tips(res.data.msg)
        }
      }
    })
  },
  onChange({
    detail: active
  }) {
    this.setData({
      active,
      type_nickName: active.title
    })
    this.getData()
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (this.data.type_nickName == '律所') {
      if (this.data.office_info.current_page >= this.data.office_info.last_page) {
        return false;
      }
      this.getMoreData()
    } else if (this.data.type_nickName == '律师') {
      if (this.data.lawyer_info.current_page >= this.data.lawyer_info.last_page) {
        return false;
      }
      this.getMoreData()
    } else if (this.data.type_nickName == '企业') {
      console.log(this.data.enterprise_info.current_page >= this.data.enterprise_info.last_page)
      if (this.data.enterprise_info.current_page >= this.data.enterprise_info.last_page) {
        return false;
      }
      this.getMoreData()
    }
  },
  getMoreData() {
    let urlStr = "",
      page = '';
    if (this.data.type_nickName == '律所') {
      urlStr = app.getNetAddresss("plugin.lawyer-platform.frontend.controllers.merchant.getLawyerFirm");
      page = this.data.office_info.current_page + 1;
    } else if (this.data.type_nickName == '律师') {
      urlStr = app.getNetAddresss("plugin.lawyer-platform.frontend.controllers.merchant.getLawyer");
      page = this.data.lawyer_info.current_page + 1;
    } else {
      urlStr = app.getNetAddresss("plugin.lawyer-platform.frontend.controllers.business.getBusiness");
      page = this.data.enterprise_info.current_page + 1;
    }
    app._postNetWork({
      url: urlStr,
      data: {
        page
      },
      success: (res) => {
        if (res.data.result == 1) {
          if (this.data.type_nickName == '律所') {
            this.data.office_info.data.concat(res.data.data.list.data);
            this.data.office_info.last_page = res.data.data.list.last_page;
            this.data.office_info.current_page = res.data.data.list.current_page;
            this.setData({
              office_info: this.data.office_info
            })
          } else if (this.data.type_nickName == '律师') {
            this.data.lawyer_info.data.concat(res.data.data.list.data);
            this.data.lawyer_info.last_page = res.data.data.list.last_page;
            this.data.lawyer_info.current_page = res.data.data.list.current_page;
            this.setData({
              lawyer_info: this.data.lawyer_info
            })
          } else {
            this.data.enterprise_info.data.concat(res.data.data.list.data);
            this.data.enterprise_info.last_page = res.data.data.list.last_page;
            this.data.enterprise_info.current_page = res.data.data.list.current_page;
            this.setData({
              enterprise_info: this.data.enterprise_info
            })
          }
        } else {
          app.tips(res.data.msg)
        }
      }
    })
  },
})